package com.spvs.approval.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spvs.approval.domain.ApprovalClassifyEntity;
import com.spvs.approval.domain.vo.ApprovalClassifyVo;
import com.spvs.approval.service.ApprovalClassifyService;
import com.spvs.common.core.web.domain.AjaxResult;
import com.spvs.common.redis.service.RedisService;
import com.spvs.common.security.utils.SecurityUtils;
import com.spvs.system.api.domain.SysRole;
import com.spvs.system.api.domain.SysUser;
import com.spvs.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 审批模板表
 */
@RestController
@RequestMapping("/approval/approvalClassify")
public class ApprovalClassifyController {
    @Autowired
    private ApprovalClassifyService approvalClassifyService;
    @Autowired
    private RedisService redisService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public AjaxResult list(@RequestParam Map<String, Object> params) {
        Page<ApprovalClassifyEntity> page = approvalClassifyService.queryPage(params);
        return AjaxResult.success(page);
    }

    /**
     * 查询所有分类（无分页）
     *
     * @return
     */
    @RequestMapping("/listAll")
    public AjaxResult listAll() {
        List<ApprovalClassifyEntity> list = approvalClassifyService.list();
        return AjaxResult.success(list);
    }

    /**
     * 信息
     */
    @RequestMapping("/info")
    public AjaxResult info(@RequestParam Integer id) {
        return AjaxResult.success(approvalClassifyService.getById(id));
    }


    /**
     * 删除
     */
    @RequestMapping("/delete")
    public AjaxResult delete(@RequestBody Integer[] ids) {
        boolean remove = approvalClassifyService.removeByIds(Arrays.asList(ids));
        if (remove) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    /**
     * 保存和修改审批模版
     *
     * @param approvalClassifyVo
     * @return
     */
    @RequestMapping("/saveOrModifyClassify")
    public AjaxResult saveOrModifyClassify(@RequestBody ApprovalClassifyVo approvalClassifyVo) throws Exception {
        return approvalClassifyService.saveOrModifyClassify(approvalClassifyVo);
    }

}
